
package com.sm.shoplook.service.customer.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sm.shoplook.constant.ResultMessage;
import com.sm.shoplook.dao.mapper.customer.CustomerMapper;
import com.sm.shoplook.domain.customer.Customer;
import com.sm.shoplook.service.customer.CustomerService;
import com.sm.shoplook.vo.base.ApiException;
import com.sm.shoplook.vo.base.ApiResult;
import com.sm.shoplook.vo.system.custom.CustomPageSearcheReqVo;

@Service
public class CustomerServiceImpl implements CustomerService {

	private static final Logger LOGGER = LoggerFactory.getLogger(CustomerServiceImpl.class);
	@Autowired
	private CustomerMapper customerMapper;

	@Override
	public ApiResult<PageInfo<Customer>> getAllCustomListPage(CustomPageSearcheReqVo customPageSearcheReqVo) {
		PageHelper.startPage(customPageSearcheReqVo.getOffset(), customPageSearcheReqVo.getPageSize());
		List<Customer> roles = customerMapper.getAllCustomListPage(customPageSearcheReqVo);
		return new ApiResult<>(ResultMessage.RESULT_SUCCESS_1, new PageInfo<>(roles));
	}

	@Override
	public ApiResult<Customer> selectCustomerById(Integer id) {
		return new ApiResult<>(ResultMessage.RESULT_SUCCESS_1, customerMapper.selectByPrimaryKey(id));
	}

	@Override
	public ApiResult updateCustomer(Customer customer) throws ApiException {
		int i = customerMapper.updateByPrimaryKeySelective(customer);
		if (i > 0) {
			return new ApiResult<>(ResultMessage.RESULT_SUCCESS_1);
		}
		throw new ApiException();
	}
}
